﻿using System;
using System.Collections.Generic;

using System.Text;

namespace Rance.Battle
{
    class 乱数表
    {
        private List<int> list = new List<int>();

        //public void Test()
        //{
        //    foreach (var item in list)
        //        Console.Write(item.ToString()+" ");
        //}

        public 乱数表()
        {
            getValue();
        }

        private void getValue()
        {
            Random r = new Random(Convert.ToInt32(DateTime.Now.Ticks % 100000000));
            for (int i = 0; i < 1000; i++)
            {
                list.Add(r.Next(100));
            }
        }

        public int GetValue()
        {
            if (list.Count == 0)
                getValue();

            var result = list[0];
            list.RemoveAt(0);
            return result;
        }

        public bool Hit(int value)
        {
            if (list.Count == 0)
                getValue();


            var result = list[0] < value;
            list.RemoveAt(0);
            return result;
        }

        public int Random(int minValue,int maxValue)
        {
            if (list.Count == 0)
                getValue();

            if (maxValue - minValue >= 100)
            {
                int value = list[0];
                list.RemoveAt(0);

                return Convert.ToInt32(minValue + (maxValue - minValue) / 100m * value);
            }
            else
            {
                int count = maxValue - minValue;
                int max = 99 - 100 % count;
                int value = list[0];
                list.RemoveAt(0);
                
                return value % count + minValue;
            }
        }

        public void Test()
        {
            int i1 = 0;
            int i2 = 4;
            for (var i = 0; i < 10000; i++)
            {
                var result = Random(i1, i2);
                if (result < i1 || result > i2)
                    Console.WriteLine(result);
            }
            Console.WriteLine("End");
        }
    }
}
